<template>
  <div id="myChart"></div>
</template>

<script>
import axios from "../../service/index";
import * as echarts from "echarts";
export default {
  data() {
    return {
      list: [],
      myChart: null,
    };
  },
  methods: {
    drawChart(list) {
      this.myChart.setOption({
        title: {
          text: "ECharts",
        },
        tooltip: {},
        xAxis: {
          data: list.map((item) => item.x),
        },
        yAxis: {},
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        series: [
          {
            name: "chuan",
            type: "pie",
            radius: [50, 250],
            center: ["50%", "50%"],
            roseType: "area",
            itemStyle: {
              borderRadius: 8,
            },
            data: list.map((item) => ({
              value: item.val,
              name: item.x,
            })),
          },
        ],
        roseType: "area",
      });
    },
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById("myChart"));
    // 绘制图表
  },
  created() {
    axios.get("/data/simpleData").then((res) => {
      this.list = res.data;
      this.drawChart(this.list);
    });
  },
};
</script>

<style scoped>
#myChart {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 600px;
}
</style>
